package com.wu.Controller;

import com.wu.DO.studentDO;
import com.wu.DO.teacherDO;
import com.wu.Service.TeacherService;
import com.wu.Util.Const;
import com.wu.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by admin on 2018/11/26.
 */
@Controller
@RequestMapping(value = "/Teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @RequestMapping(value = "login", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<teacherDO> login(String username, String password, HttpSession session) {

        ServerResponse<teacherDO> response = teacherService.login(username, password);
        if (response.isSuccess()) {
            session.setAttribute(Const.CURRENY_USER, response.getData());

        }
        return response;
    }

    @RequestMapping(value = "logout", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> logout(HttpSession session) {
        session.removeAttribute(Const.CURRENY_USER);
        return ServerResponse.createBySuccess();
    }
    @RequestMapping(value="addGraduate",method=RequestMethod.GET)
    @ResponseBody
    public ServerResponse<String> add(Integer projectId,String title,String introduction,String tname,Integer teacherId){
        ServerResponse<String> response=teacherService.addGraduate(projectId,title,introduction,tname,teacherId);
        return response;
    }
}